﻿
namespace Project
{
    using System;
    using System.Text;
    using System.Collections.Generic;


    /// <summary>
    /// Provides basic functionality of domain logic controller
    /// </summary>
    public abstract class DomainControllerBase : IDisposable
    {       

        protected DomainControllerBase2(IStorageController context, IServiceProvider provider)
        {
            m_Storage = context;
            m_IsDIContext = context is IStorageController;
        }

        /// <summary>
        /// Auto complete transaction if controller is destroy
        /// </summary>
        public bool AutoComplete { get; private set; }

        public IStorageController Storage { get { return m_Storage; } }

        #region IDisposable members

        protected abstract void Dispose(bool disposeManaged);

        public void Dispose()
        {          
            Dispose(true);

            ///utilize storage code
            if (m_Storage != null & m_IsDIContext)
                m_Storage.Dispose();


            GC.SuppressFinalize(this);
        }

        #endregion

        ~DomainControllerBase2()
        {
            Dispose(false);
        }
        
        private readonly bool m_IsExternal = false;
        private readonly bool m_IsDIContext = false;
        private readonly IStorageController m_Storage = null;
    }
}
